class Idris2 < Formula
  desc "Pure functional programming language with dependent types"
  homepage "https://www.idris-lang.org/"
  url "https://github.com/idris-lang/Idris2/archive/v0.2.2.tar.gz"
  sha256 "e6eef9010a9ccd4859135d548f1b6803a80b5aa9da88b69075712bb3c0acd09b"
  license "BSD-3-Clause"
  head "https://github.com/idris-lang/Idris2.git"

  bottle do
    cellar :any
    sha256 "3ae7fb814b623c3f84cbacbd49e68214aeeed3042befe5016c81760338798a40" => :big_sur
    sha256 "10109489da074ad0cf45b0772452a67d5c5ba8f1b311913c68270ba49c577c5e" => :catalina
    sha256 "c467c0d4b91db800840586a0786363e2b5f13c4f3be69bc59648d0b9d94c4752" => :mojave
  end

  depends_on "coreutils" => :build
  depends_on "chezscheme"

  def install
    ENV.deparallelize
    scheme = Formula["chezscheme"].bin/"chez"
    system "make", "bootstrap", "SCHEME=#{scheme}", "PREFIX=#{libexec}"
    system "make", "install", "PREFIX=#{libexec}"
    # idris2.so is an executable file generated by Idris2
    bin.install "#{libexec}/bin/idris2_app/idris2.so" => "idris2"
    lib.install_symlink Dir["#{libexec}/lib/*.dylib"]
  end

  test do
    (testpath/"hello.idr").write <<~EOS
      module Main
      main : IO ()
      main = putStrLn "Hello, Homebrew!"
    EOS

    system bin/"idris2", "hello.idr", "-o", "hello"
    assert_equal "Hello, Homebrew!",
                 shell_output("./build/exec/hello_app/hello.so").chomp
  end
end
